package cn.edu.scau.cmi.chenmiaopeng.interProgramming;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollBar;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextArea;
import javafx.scene.input.ScrollEvent;
import javafx.fxml.FXMLLoader;
public class InterProgrammingController {
	   @FXML
	    private Button graduate;
       @FXML
	    private Button under;
       @FXML
       private TextArea textArea;
       private FXMLLoader loader;
       Student student;
       public void setFXMLLoader(FXMLLoader loader) {
    	   this.loader = loader;
       }
//       public void initialize(){
//    	   
//       }
       @FXML
       public void clickButton(ActionEvent e) {
    	   Button clickButton = (Button)e.getSource();
    	   if(clickButton==under) {
    		   student = new UndergraduateStudent();
    		   textArea.appendText(student.learning()+"\n");
    	   }
    	   else if(clickButton==graduate) {
    		   student = new GraduateStudent();
    		   textArea.appendText(student.learning()+"\n");
    	   }
       }
       public void judgeFullAndClear() {
           ChangeListener<Boolean> listener = new ChangeListener<Boolean>() {
            @Override
			public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
				if(newValue==true) {
				   textArea.clear();
				}
			}
    	  };
    	  
    	   ScrollBar scrollBar = (ScrollBar) textArea.lookup(".scroll-bar:vertical");  //scrollBar初始时不存在
    	   scrollBar.visibleProperty().addListener(listener);
       }
}
//int lines = textArea.getPrefRowCount();
//System.out.println("PrefRowCount:"+lines);
//String strArea = textArea.getText();
//int lineCount = strArea.split("\n").length+1;
//System.out.println("已输入的行数为:"+lineCount);

//EventHandler eventHandler = new EventHandler<ScrollEvent>() {
//   @Override
//	  public void handle(ScrollEvent event) {
// 	  System.out.println("滚动动作");
//		if(event.getSource()==ScrollEvent.SCROLL_STARTED) {
//			System.out.println("开始滚动");
//		}
//		else if(event.getSource()==ScrollEvent.SCROLL_FINISHED) {
//			System.out.println("滚动结束");
//		}
//	  }
//};
//textArea.setOnScroll(eventHandler);
//textArea.scrollTopProperty().addListener(listener);